package com.shijiwei.lifthelper.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shijiwei.lifthelper.R;
import com.shijiwei.lifthelper.bean.Weather;
import com.shijiwei.lifthelper.fragment.WeatherFragment;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by sjw on 2015/12/14.
 */
public class WeatherAdapter extends AppBaseAdapter {

    private  List<Weather.ResultEntity.DataEntity.WeatherEntity> list;
    public WeatherAdapter(List<Weather.ResultEntity.DataEntity.WeatherEntity> list, Context context) {
        super(list, context);
        this.list = list;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = inflater.inflate(R.layout.item_gridview_weather,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        WeatherFragment.judgeWeatherIcon(list.get(position).getInfo().getDay().get(1),holder.ivWeather);
        holder.tvWeather.setText(list.get(position).getInfo().getDay().get(1));
        holder.tvTemperature.setText(list.get(position).getInfo().getDay().get(2)+" - "+list.get(position).getInfo().getNight().get(2)+"℃" );
        holder.tvWeek.setText("周"+list.get(position).getWeek());
        return convertView;
    }
    class ViewHolder extends BaseViewHolder{

        public ViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this,convertView);
        }
        @ViewInject(R.id.iv_weather)
        ImageView ivWeather;
        @ViewInject(R.id.tv_weather)
        TextView tvWeather;
        @ViewInject(R.id.tv_temperature)
        TextView tvTemperature;
        @ViewInject(R.id.tv_week)
        TextView tvWeek;
    }
}
